package com.gxa.controller.lgr.appointment;

import com.gxa.common.R;
import com.gxa.common.vo.AppointmentPageRequest;
import com.gxa.service.AppointmentManagementService;
import com.gxa.utils.HeaderUtils;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author MacieSerenity
 * 关于预约管理的功能
 */
@Controller
@RequestMapping("/appointment/management")
@RequiresRoles(value = {"超级管理员","院长","主任","秘书","助理"},logical = Logical.OR)
@Api(value = "预约管理", tags = "预约管理数据接口")
public class AppointmentManagementController {

    @Autowired
    AppointmentManagementService appointmentManagementService;

    /**
     * 分页请求预约管理信息
     *
     * @param appointmentPageRequest 请求参数
     * @return 分页预约信息
     */
    @ApiOperation(value = "分页请求预约管理信息", httpMethod = "POST", notes = "返回固定数量的分页数据", response = R.class)
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 404, message = "找不到页面"), @ApiResponse(code = 500, message = "后台服务错误")})
    @PostMapping("/findAppointmentList")
    @ResponseBody
    public R findAppointmentList(@RequestBody(required = false)
                                     @ApiParam(name = "appointmentPageRequest",value = "请求过来的Page信息",required = true) AppointmentPageRequest appointmentPageRequest) {
        return appointmentManagementService.findAllAppointment(appointmentPageRequest);
    }

    /**
     * 根据条件查询后返回的预约管理信息
     *
     * @param appointmentPageRequest 查询对象
     * @return 分页预约信息
     */
    @ApiOperation(value = "根据条件查询后返回的预约管理信息", httpMethod = "POST", notes = "返回固定数量（PageSize）的分页数据", response = R.class)
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 404, message = "找不到页面"), @ApiResponse(code = 500, message = "后台服务错误")})
    @PostMapping("/getAppointmentQuery")
    @ResponseBody
    public R queryAppointmentList(@RequestBody(required = false)
                                      @ApiParam(name = "appointmentPageRequest",value = "请求过来的Page信息",required = true)
                                      AppointmentPageRequest appointmentPageRequest) {
        return appointmentManagementService.findAllAppointment(appointmentPageRequest);
    }

    /**
     * 根据传送的病患ID创建一个新的预约单
     *
     * @param patientId 病患ID
     * @return R 统一返回对象，返回状态码和信息
     */
    @ApiOperation(value = "根据传送的病患ID创建一个新的预约单", httpMethod = "POST", notes = "返回R", response = R.class)
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 404, message = "找不到页面"), @ApiResponse(code = 500, message = "后台服务错误")})
    @PostMapping("/addAppointment")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "patientId", value = "病患ID", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "days", value = "预约天数", paramType = "query", dataType = "String", required = true)
    })
    @ResponseBody
    public R addAppointment(@RequestParam("patientId") Integer patientId,@RequestParam("days")Integer days,HttpServletRequest request) {
        Integer userID = HeaderUtils.getUserID(request);
        return appointmentManagementService.addAppointmentById(userID,patientId,days);
    }

    /**
     * 根据传送的病患ID修改预约单的状态
     *
     * @param id 预约单的ID
     * @return R同意返回对象
     */
    @ApiOperation(value = "根据传送的病患ID修改预约单的状态", httpMethod = "POST", notes = "返回R", response = R.class)
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 404, message = "找不到页面"), @ApiResponse(code = 500, message = "后台服务错误")})
    @PostMapping("/handleAppointment")
    @ResponseBody
    public R handleAppointment(@RequestParam("id") Integer id) {
        return appointmentManagementService.handleAppointmentById(id);
    }

    /**
     * 根据传送的病患ID进行删除
     *
     * @param id 病患ID
     * @return R
     */
    @ApiOperation(value = "根据传送的病患ID进行删除", httpMethod = "POST", notes = "返回R", response = R.class)
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 404, message = "找不到页面"), @ApiResponse(code = 500, message = "后台服务错误")})
    @PostMapping("/deleteAppointment")
    @ResponseBody
    public R deleteAppointment(@RequestParam("id") Integer id) {
        return appointmentManagementService.deleteAppointmentById(id);
    }

}
